<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/common/taglib.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0"/>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>MCU MANAGER</title>
	<%@ include file="/WEB-INF/jsp/common/cssjs2.jsp" %>
	
	<script type="text/javascript">
		$(function(){
			$('.easyui-validatebox').validatebox();
			$('.easyui-validatebox[required]').after("<font color='red'> *</font>");
		});
		
		function doSubmit(){
			$('#id_form').form('submit', {
		        url:"<c:url value='/app/manage/mcu'/>",
		        onSubmit: function(){
		        	if($('.easyui-validatebox').validatebox("isValid")==false){
		        		return false;
		        	}else if(isNameExist()){
		        		alert(messages.getMsg("mcu.error.nameExist",[$("#id_name").val()]));
		        		return false;
		        	}else{
						return true;
					}
		        },
		        success:function(data){
					//alert(data);
					parent.mcuObj.reload();
					parent.closeWin();
		        }
			});
		}
		
		function isNameExist(){
			var ret=false;
			var _name=$("#id_name").val();
			var _preName="<c:out value='${mcu.name}'/>";
			
			if("${param.opt}"=="modify"&&_name==_preName){//whether is the same name in the modify page
				ret=false;
			}else{
				$.ajax({
					url:"<c:url value='/app/manage/mcu/check'/>",
					async:false,
					type:"GET",
					data:{
						name:$("#id_name").val(),
						times:new Date().toString()
					},
					success:function(data){
						if(data=="true")
							ret=true;
					}
				});
			}
			
			return ret;
		}
	</script>
	
	<style type="text/css">
	    html, body {
	        width: 100%;
	        height: 100%;
	        margin: 0px;
	        overflow: hidden;
	    }
	</style>
</head>
<body class="dialog">
	<div id="id_mcu" class="table-container">
		<form id="id_form" method="post">
		<c:if test="${param.opt=='modify'}">
			<input type="hidden" value="PUT" name="_method">
		</c:if>
		<input type="hidden" value="${mcu.id}" name="id">
		<table>
			<tr>
				<td><fmt:message key='form.mcu.name'/></td>
				<td><input type="text" id="id_name" value="${mcu.name}" name="name" class="input-text easyui-validatebox" required="true"></td>
			</tr>
			<tr>
				<td><fmt:message key='form.mcu.address'/></td>
				<td><input type="text" name="address" value="${mcu.address}" class="input-text easyui-validatebox" required="true"></td>
			</tr>
			<tr>
				<td><fmt:message key='form.mcu.port'/></td>
				<td><input type="text" name="port" value="<c:out value='${mcu.port}' default='5040'/>" class="input-text easyui-validatebox" validType="positiveInt" required="true"></td>
			</tr>
			<tr>
				<td><fmt:message key='form.mcu.manager.protocol'/></td>
				<td><input type="text" name="managerprotocol" value="<c:out value='${mcu.managerprotocol}' default='http'/>" class="input-text easyui-validatebox"></td>
			</tr>
			<tr>
				<td><fmt:message key='form.mcu.manager.port'/></td>
				<td><input type="text" name="managerport" value="<c:out value='${mcu.managerport}' default='8080'/>" class="input-text easyui-validatebox" validType="positiveInt"></td>
			</tr>
			<tr>
				<td><fmt:message key='form.mcu.manager.name'/></td>
				<td><input type="text" name="managername" value="${mcu.managername}" class="input-text easyui-validatebox"></td>
			</tr>
			<tr>
				<td><fmt:message key='form.mcu.user'/></td>
				<td><input type="text" name="user" value="${mcu.user}" class="input-text easyui-validatebox" required="true"></td>
			</tr>
			<tr>
				<td><fmt:message key='form.mcu.password'/></td>
				<td><input type="password" name="password" value="${mcu.password}" class="input-text easyui-validatebox" required="true"></td>
			</tr>
			<tr>
				<td><fmt:message key='form.mcu.description'/></td>
				<td><textarea rows="5" name="description" class="input-text">${mcu.description}</textarea></td>
			</tr>
			<tr>
				<td colspan="2">
					<p align="center">
                        <input type="button" onclick="doSubmit();" class="mybtn" value="<fmt:message key='btn.ok'/>">
						<button onclick="parent.closeWin();" class="mybtn"><fmt:message key='btn.cancel'/></button>
					</p>
				</td>
			</tr>
		</table>
		</form>
	</div>
</body>
</html>